<template>
  <div class="search-panel">
    <div class="search-form">
      <div class="form-row">
        <div class="form-item">
          <label>开始日期：</label>
          <el-date-picker
            :model-value="searchForm.startDate"
            @update:model-value="updateField('startDate', $event)"
            type="date"
            placeholder="请选择开始日期"
            value-format="YYYY-MM-DD"
          />
        </div>
        
        <div class="form-item">
          <label>结束日期：</label>
          <el-date-picker
            :model-value="searchForm.endDate"
            @update:model-value="updateField('endDate', $event)"
            type="date"
            placeholder="请选择结束日期"
            value-format="YYYY-MM-DD"
          />
        </div>
        
        <div class="form-item">
          <label>场次：</label>
          <el-select 
            :model-value="searchForm.periodName"
            @update:model-value="updateField('periodName', $event)"
            placeholder="请选择场次"
            clearable
          >
            <el-option label="全部" value=""></el-option>
            <el-option label="上午场次" value="上午场次"></el-option>
            <el-option label="下午场次" value="下午场次"></el-option>
            <el-option label="晚上场次" value="晚上场次"></el-option>
          </el-select>
        </div>
        
        <div class="form-item">
          <label>排序方式：</label>
          <el-select 
            :model-value="searchForm.sortType"
            @update:model-value="updateField('sortType', $event)"
            placeholder="请选择排序方式"
          >
            <el-option label="创建时间(倒序)" value="desc"></el-option>
            <el-option label="创建时间(正序)" value="asc"></el-option>
          </el-select>
        </div>
      </div>
      
      <div class="form-row">
        <div class="form-item">
          <label>综合搜索：</label>
          <el-input
            :model-value="searchForm.searchText"
            @update:model-value="updateField('searchText', $event)"
            placeholder="支持搜索联系人姓名、电话、预约编号"
            clearable
            @keyup.enter="$emit('search')"
          />
        </div>
      </div>
      
      <div class="form-actions">
        <button class="search-btn" @click="$emit('search')">
          <span class="btn-content">
            <span class="btn-icon">🔍</span>
            查询预约
          </span>
        </button>
        <button class="reset-btn" @click="$emit('reset')">
          <span class="btn-content">
            <span class="btn-icon">🔄</span>
            重置条件
          </span>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  searchForm: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['update:searchForm', 'search', 'reset'])

const updateField = (field, value) => {
  const newForm = { ...props.searchForm, [field]: value }
  emit('update:searchForm', newForm)
}
</script>

<style scoped>
/* 查询条件样式 */
.search-panel {
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
  padding: 25px;
  margin-bottom: 20px;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.form-item {
  flex: 1;
}

.form-item label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
  font-size: 14px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.search-btn, .reset-btn {
  padding: 12px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
}

.search-btn:hover, .reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.search-btn:active, .reset-btn:active {
  transform: translateY(0);
}

.btn-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  font-size: 1rem;
}

@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
  }
  
  .form-item {
    margin-bottom: 15px;
  }
  
  .form-actions {
    flex-direction: column;
    align-items: flex-end;
  }
  
  .search-btn, .reset-btn {
    padding: 10px 16px;
    font-size: 0.9rem;
    min-height: 40px;
  }
}
</style> 